﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Editor
{
    public partial class PreferencesWindow : Form
    {
        public PreferencesWindow()
        {
            InitializeComponent();

            m_CboUpAxis.SelectedIndex = (Properties.Settings.Default.ZAxisUp) ? 1 : 0;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            bool bZUp = m_CboUpAxis.SelectedIndex == 1;
            bool bRestartRequired = (bZUp != Properties.Settings.Default.ZAxisUp);

            if (bRestartRequired)
            {
                DialogResult res = MessageBox.Show(this,
                                                    "You have made changes to the settings that requires a restart in order to take effect, " +
                                                    "and could result in undefined behaviour or lost work if this is not done.\n\n" +
                                                    "If you select Yes, please restart the application immediately.\n" +
                                                    "If you select No, your settings will remain unaltered.\n" +
                                                    "If you select Cancel, you will be able to modify the settings you have chosen.\n\n" +
                                                    "Do you want to continue?",
                                                    "Restart Required",
                                                    MessageBoxButtons.YesNoCancel);
                if (res == DialogResult.Cancel)
                {
                    return;
                }
                else if (res == DialogResult.No)
                {
                    DialogResult = DialogResult.Cancel;
                    this.Close();
                }
                else
                {
                    Properties.Settings.Default.ZAxisUp = bZUp;
                    Properties.Settings.Default.Save();

                    DialogResult = DialogResult.OK;
                    this.Close();
                }
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
